
include('entity');

var INIT_RADIUS = 15;

new_class(
  'BlackHole',
  function(x, y) {
    Entity.call(this, x, y, 0)
    this.force = 100;
    this.ticks = 0;
    this.radius = INIT_RADIUS;
  },
  {
    // Overrides Entity.draw
    draw: function draw(d) {
      var context = d.getContext();
      var gradient = context.createRadialGradient(0,0,0, 0,0,30);
      gradient.addColorStop(0, "black");
      gradient.addColorStop(1, "purple");

      context.beginPath();
      context.arc(0, 0, this.radius, 0, Math.PI * 2, false);
      context.closePath();
      context.fillStyle = gradient;
      context.fill();
      context.strokeStyle = "#220022";
      context.stroke();

      context.beginPath();
      context.arc(0, 0, this.radius - (this.ticks/2.0 % this.radius), 0, Math.PI * 2, false);
      context.closePath();
      context.strokeStyle = "#BB00BB";
      context.stroke();
    },
    update : function() {
      this.ticks += 1;
      this.radius = 3 + INIT_RADIUS - INIT_RADIUS * (this.ticks*30) / 2000;
      // TODO(stevet): On one hand, this is a bit of a hack to prevent black
      // hole rendering from crashing the game due to a zero size. On the
      // other hand, I sort of like how the black hole lingers as it dies.
      if (this.radius < 1)
        this.radius = 1;
    }
  },
  Entity);
